<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>组件的事件</h2>
      <child @abc="fn"></child>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const Child = {
        // 组件可以显式地通过 emits 选项来声明它要触发的事件：
        // 如果emits写成数组的语法，那和不写是没有区别的
        // emits: ["abc"],

        // 写成对象是用来校验自定义事件的参数是否正确
        emits: {
          abc(v) {
            const type = typeof v;
            return type === "number";
          },
        },
        template: `
          <div>child子组件 - <button @click="$emit('abc', '888')">btn</button></div>
        `,
      };

      createApp({
        data() {
          return {};
        },
        methods: {
          fn() {
            console.log("fn");
          },
        },
        components: {
          Child,
        },
      }).mount("#app");
    </script>
  </body>
</html>
